+1999-08-09 Federico Mena Quintero <federico@nuclecu.unam.mx>
+
+ * src/io-png.c (image_save): Fixed compiler warnings. Fixed write
+ to unallocated memory (row_ptr), and fixed its type as well. Take
+ into account the ArtPixbuf's rowstride when assigning the row
+ pointers.
+
+ * src/gdk-pixbuf.c: Fixup includes.
+
+ * src/gdk-pixbuf-io.c: Likewise.
+
Sat Jul 31 19:19:47 CEST 1999
* src/gdk-pixbuf-io.c:
* Author:
* Miguel de Icaza (miguel@gnu.org)
*/
+
#include <config.h>
#include <stdio.h>
+#include <string.h>
#include <glib.h>
#include <gmodule.h>
#include "gdk-pixbuf.h"
if (buffer [0] != 0xff || buffer [1] != 0xd8)
return FALSE;
-
+
return TRUE;
}
if (size < 10)
return FALSE;
- if (buffer [0] == 'M' &&
- buffer [1] == 'M' &&
- buffer [2] == 0 &&
+ if (buffer [0] == 'M' &&
+ buffer [1] == 'M' &&
+ buffer [2] == 0 &&
buffer [3] == 0x2a)
return TRUE;
- if (buffer [0] == 'I' &&
- buffer [1] == 'I' &&
- buffer [2] == 0x2a &&
+ if (buffer [0] == 'I' &&
+ buffer [1] == 'I' &&
+ buffer [2] == 0x2a &&
buffer [3] == 0)
return TRUE;
-
+
return FALSE;
}
{
if (size < 20)
return FALSE;
-
+
if (strncmp (buffer, "GIF8", 4) == 0)
return TRUE;
-
+
return FALSE;
}
{
if (size < 20)
return FALSE;
-
+
if (strncmp (buffer, "/* XPM */", 9) == 0)
return TRUE;
-
+
return FALSE;
}
{
if (size < 20)
return FALSE;
-
+
if (buffer [0] != 'B' || buffer [1] != 'M')
return FALSE;
-
+
return TRUE;
}
{ NULL, NULL, NULL, NULL, NULL }
};
-static int
-image_file_format (const char *file)
-{
- FILE *f = fopen (file, "r");
-
- if (!f)
- return -1;
-}
-
static void
image_handler_load (int idx)
{
char *path;
GModule *module;
void *load_sym, *save_sym;
-
- module_name = g_strconcat ("pixbuf-",
+
+ module_name = g_strconcat ("pixbuf-",
file_formats [idx].module_name, NULL);
path = g_module_build_path (PIXBUF_LIBDIR, module_name);
g_free (module_name);
n = fread (&buffer, 1, sizeof (buffer), f);
if (n == 0){
- fclose (f);
+ fclose (f);
return NULL;
}
* Miguel de Icaza (miguel@gnu.org)
* Mark Crichton (crichton@gimp.org)
*/
+
#include <config.h>
#include <glib.h>
#include <math.h>
#include <libart_lgpl/art_misc.h>
-#include <libart_lgpl/art_rgb_affine.h>
+#include <libart_lgpl/art_affine.h>
+#include <libart_lgpl/art_pixbuf.h>
+#include <libart_lgpl/art_rgb_pixbuf_affine.h>
#include <libart_lgpl/art_alphagamma.h>
#include "gdk-pixbuf.h"
gdk_pixbuf_ref (GdkPixBuf *pixbuf)
{
g_return_if_fail (pixbuf != NULL);
-
+
pixbuf->ref_count++;
}
{
g_return_if_fail (pixbuf != NULL);
g_return_if_fail (pixbuf->ref_count == 0);
-
+
pixbuf->ref_count--;
if (pixbuf->ref_count)
gdk_pixbuf_destroy (pixbuf);
GdkPixBuf *
gdk_pixbuf_scale (GdkPixBuf *pixbuf, gint w, gint h)
{
- GdkPixBuf *spb;
art_u8 *pixels;
gint rowstride;
double affine[6];
alphagamma = NULL;
affine[1] = affine[2] = affine[4] = affine[5] = 0;
-
-
+
+
affine[0] = w / (double)(pixbuf->art_pixbuf->width);
affine[3] = h / (double)(pixbuf->art_pixbuf->height);
rowstride = w * 3;
pixels = art_alloc (h * rowstride);
- art_rgb_pixbuf_affine( pixels, 0, 0, w, h, rowstride,
+ art_rgb_pixbuf_affine (pixels, 0, 0, w, h, rowstride,
pixbuf->art_pixbuf,
affine, ART_FILTER_NEAREST, alphagamma);
if (pixbuf->art_pixbuf->has_alpha)
/* should be rgba */
- art_pixbuf = art_pixbuf_new_rgb(pixels, w, h, rowstride);
- else
- art_pixbuf = art_pixbuf_new_rgb(pixels, w, h, rowstride);
+ art_pixbuf = art_pixbuf_new_rgb(pixels, w, h, rowstride);
+ else
+ art_pixbuf = art_pixbuf_new_rgb(pixels, w, h, rowstride);
art_pixbuf_free (pixbuf->art_pixbuf);
pixbuf->art_pixbuf = art_pixbuf;
GdkPixBuf *
gdk_pixbuf_rotate (GdkPixBuf *pixbuf, gdouble angle)
{
- GdkPixBuf *rotate;
art_u8 *pixels;
gint rowstride, w, h;
gdouble rad;
affine, ART_FILTER_NEAREST, alphagamma);
if (pixbuf->art_pixbuf->has_alpha)
/* should be rgba */
- art_pixbuf = art_pixbuf_new_rgb(pixels, w, h, rowstride);
- else
- art_pixbuf = art_pixbuf_new_rgb(pixels, w, h, rowstride);
+ art_pixbuf = art_pixbuf_new_rgb(pixels, w, h, rowstride);
+ else
+ art_pixbuf = art_pixbuf_new_rgb(pixels, w, h, rowstride);
art_pixbuf_free (pixbuf->art_pixbuf);
pixbuf->art_pixbuf = art_pixbuf;
GdkPixBuf *image_load(FILE *f)
{
int w,h,i,j;
- art_u8 *pixels=NULL, *dptr, *fptr, *pptr;
+ art_u8 *pixels=NULL, *dptr;
unsigned char *lines[4], /* Used to expand rows, via rec_outbuf_height, from
the header file:
"* Usually rec_outbuf_height will be 1 or 2, at most 4." */
}
pixbuf->ref_count = 0;
pixbuf->unref_func = NULL;
-
+
return pixbuf;
}
png_infop info_ptr;
art_u8 *data;
gint y, h, w;
- png_bytep row_ptr;
+ png_bytepp row_ptr;
png_color_8 sig_bit;
gint type;
-
- g_return_val_if_fail(file != NULL, NULL);
- g_return_val_if_fail(pixbuf != NULL, NULL);
+
+ g_return_val_if_fail(file != NULL, FALSE);
+ g_return_val_if_fail(pixbuf != NULL, FALSE);
h = pixbuf->art_pixbuf->height;
w = pixbuf->art_pixbuf->width;
NULL, NULL, NULL);
if (png_ptr == NULL) {
fclose(file);
- return NULL;
+ return FALSE;
}
info_ptr = png_create_info_struct(png_ptr);
if (info_ptr == NULL) {
fclose(file);
png_destroy_write_struct(&png_ptr, (png_infopp) NULL);
- return NULL;
+ return FALSE;
}
if (setjmp(png_ptr->jmpbuf)) {
fclose(file);
png_destroy_write_struct(&png_ptr, (png_infopp) NULL);
- return NULL;
+ return FALSE;
}
png_init_io(png_ptr, file);
png_set_packing(png_ptr);
data = pixbuf->art_pixbuf->pixels;
+ row_ptr = g_new(png_byte *, h);
- for (y = 0; y < h; y++) {
+ for (y = 0; y < h; y++)
+ row_ptr[y] = data + y * pixbuf->art_pixbuf->rowstride;
+#if 0
+ {
if (pixbuf->art_pixbuf->has_alpha)
row_ptr[y] = data + (w * y * 4);
else
row_ptr[y] = data + (w * y * 3);
}
+#endif
png_write_image(png_ptr, row_ptr);
+ g_free (row_ptr);
+
png_write_end(png_ptr, info_ptr);
png_destroy_write_struct(&png_ptr, (png_infopp) NULL);
return TRUE;
}
-
color->transparent = FALSE;
color_name = xpm_extract_color(buffer);
-
+
if ((color_name == NULL) || (g_strcasecmp(color_name, "None") == 0)
|| (gdk_color_parse(color_name, &color->color) == FALSE)) {
color->transparent = TRUE;